package com.stylefeng.guns.modular.system.task;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.stylefeng.guns.core.common.constant.state.GpType;
import com.stylefeng.guns.core.common.constant.state.HsgtType;
import com.stylefeng.guns.core.common.constant.state.ZgpType;
import com.stylefeng.guns.core.support.DateTimeKit;
import com.stylefeng.guns.core.util.RestUtil;
import com.stylefeng.guns.core.util.WeekUtils;

/**
 * 股票数据导入
 * @author haqiaolong
 *
 */
@Component
public class GpDataManager{
	
	private Logger log = LoggerFactory.getLogger(GpImportTask.class);
	
	@Autowired
	private GpImportTask gpImportTask;
	
	@Autowired
	private ZgpImportTask zgpImportTask;
	
	@Autowired
	private BrankImportTask brankImportTask;
	
	@Autowired
	private HyBrankImportTask hybrankImportTask;
	
	@Autowired
	private SmImportTask smImportTask;
	
	@Autowired
	private MkDataImportTask mkDataImportTask;
	
	@Autowired
	private ControlImportTask controlImportTask;
	
	@Autowired
	private DjgImportTask djgImportTask;
	
	@Autowired
	private HsgtImportTask hsgtImportTask;
	
	@Autowired
	private GpcImportTask gpcImportTask;
	
	@Autowired
	private ZjGzImportTask zjGzImportTask;
	
	@Autowired
	private RealTimeGpImportTask readTimeGpImportTask;
	
	@Autowired
	private IndustryImportTask industryImportTask;
	
	@Autowired
	private YouziImportTask youziImportTask;
	
	@Autowired
	private HsgtStatsImportTask hsgtStatsImportTask;
	
	@Autowired
	private CurFengKouImportTask curFengKouImportTask;
	
	@Autowired
	private PlatImportTask platImportTask;
	
	@Autowired
	private GpConceptImportTask gpConceptImportTask;
	
	@Autowired
	private GpcStatImportTask gpcStatImportTask;
	
	@Autowired
	private YdayImportTask ydayImportTask;
	
	@Autowired
	private GpRemarkImportTask gpRemarkImportTask;
	
	@Autowired
	private JjGpcImportTask jjGpcImportTask;
	
	@Autowired
	private GpcWtImportTask gpcWtImportTask;

	@Autowired
	private DbqImportTask dbqImportTask;

	@Autowired
	private JxBkImportTask jxBkImportTask;
	
//	@Autowired
//	private GgMoneyTotalImportTask ggMoneyTotalImportTask;
	
//	@Autowired
//	private RealPriceImportTask realPriceImportTask;
	
	private static boolean isHoliday = false;

//	@Scheduled(fixedRate = 3000)
//	public void test(){
//		ydayImportTask.execute(isHoliday);
//		System.out.println("test");
//	}
	
	
	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0 0 8 * * ?")
	public void isHoliday(){
		RestUtil.clean();
		isHoliday = WeekUtils.isHolidayByK780(DateTimeKit.format(new Date(), "yyyyMMdd"));
		log.info("get isHoliday is complete!");
	}

	@Scheduled(fixedRate = 60000)
	//@Scheduled(cron="0 0 20 * * ?")
	public void dbqImport(){
		dbqImportTask.execute();
		log.info("get dbq data is complete!");
	}

	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0/5 * 9-14 * * ?")
	public void jxbkImport(){
		jxBkImportTask.execute(isHoliday);
		log.info("get jxbk data is complete!");
	}
	
	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0 0 20 * * ?")
	public void remarkImport(){
		gpRemarkImportTask.execute(isHoliday);
		log.info("get remark data is complete!");
	}

	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0/3 * 9-14 * * ?")
	public void ydayImport(){
		ydayImportTask.execute(isHoliday);
		log.info("get yday data is complete!");
	}

	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0/10 * 9 * * ?")
	public void jjGpcImport(){
		jjGpcImportTask.execute(isHoliday);
		log.info("get jj data is complete!");
	}

	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0/2 * 9-14 * * ?")
	public void IndustryImport(){
		industryImportTask.execute(isHoliday);
		log.info("get industry data is complete!");
	}

	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0/5 * 9-14 * * ?")
	public void platImport(){
		platImportTask.execute(isHoliday);
		log.info("get plat data is complete!");
	}

	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0/5 * 9-14 * * ?")
	public void gpcStatImport(){
		gpcStatImportTask.execute(isHoliday);
		log.info("get gpc stat is complete!");
	}

	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0/10 * 9-14 * * ?")
	public void CruFengKouImport(){
		curFengKouImportTask.execute(isHoliday);
		log.info("get cur fengkou data is complete!");
	}

	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0 30 17 * * ?")
	public void hsgtStatsImport(){
		hsgtStatsImportTask.execute(isHoliday,HsgtType.A);
		hsgtStatsImportTask.execute(isHoliday,HsgtType.B);
		log.info("get hsgt stats data is complete!");
	}


	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0/5 * 9-14 * * ?")
	public void realTimeImport(){
		gpcWtImportTask.execute(isHoliday);
//		readTimeGpImportTask.execute(isHoliday);
		log.info("get realTime data is complete!");
	}


	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0 0 10-16/2 * * ?")
	public void mkImport(){
		mkDataImportTask.execute(isHoliday);
		log.info("get mk data is complete!");
	}

	/**
	 * A股
	 */
	//@Scheduled(fixedRate = 3000)
	@Scheduled(cron="0 30 16 * * ?")
	public void gudongImport(){
		//股票数据导入
		gpImportTask.execute(isHoliday,GpType.A);
		gpImportTask.execute(isHoliday,GpType.C);
		gpImportTask.execute(isHoliday,GpType.S);
		gpImportTask.execute(isHoliday,GpType.Z);
		controlImportTask.execute(isHoliday);
		zjGzImportTask.execute(isHoliday);
		gpConceptImportTask.execute(isHoliday);
		log.info("get gupiao data is complete!");
	}

	//十大股东导入
	@Scheduled(cron="0 0 22 * * ?")
	//@Scheduled(fixedRate = 3000)
	public void zgudongImport(){
		zgpImportTask.execute(isHoliday,ZgpType.A);
		zgpImportTask.execute(isHoliday,ZgpType.B);
		smImportTask.execute(isHoliday);
		log.info("get gudong data is complete!");
	}

	//营业部排行
	@Scheduled(cron="0 0 23 * * ?")
	//@Scheduled(fixedRate = 3000)
	public void brankImport(){
		brankImportTask.execute(isHoliday);
		log.info("get brank data is complete!");
	}

	//活跃营业部
	@Scheduled(cron="0 30 17 * * ?")
	//@Scheduled(fixedRate = 3000)
	public void hybrankImport(){
		hybrankImportTask.execute(isHoliday);
		log.info("get hy brank data is complete!");
	}

	//股票池
	@Scheduled(cron="0 30 19 * * ?")
	//@Scheduled(fixedRate = 3000)
	public void gpcImport(){
		gpcImportTask.execute(isHoliday);
		log.info("get gpc data is complete!");
	}

	//沪深股通
	@Scheduled(cron="0 30 18 * * ?")
	//@Scheduled(fixedRate = 3000)
	public void hsgtImport(){
		hsgtImportTask.execute(isHoliday,HsgtType.A);
		hsgtImportTask.execute(isHoliday,HsgtType.B);
		hsgtImportTask.execute(isHoliday,HsgtType.C);
		log.info("get hsgt data is complete!");
	}

	//董监高
	@Scheduled(cron="0 30 17 * * ?")
	//@Scheduled(fixedRate = 3000)
	public void djgImport(){
		djgImportTask.execute(isHoliday);
		log.info("get djg data is complete!");
	}
}
